<!DOCTYPE html>
<html lang="zh-Hans" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>随访信息列表</title>
    <div th:replace="cqzd/common/common-resource :: global-header"></div>
</head>
<body>
<!--<div style="padding:5px;">
    <div class="search-condition">
        <div class="list">
            <div id="form1">
                <table style="width:80%;padding:5px;" class="table" >
                    <tr>
                        <td>短信模板名称：
                            <input class="mini-textbox" name="tmplName" style="width:120px" onEnter='_CommListener.onKeyEnter'/>

                            <input class="mini-button" text="查询" onclick="search" iconCls="icon-search"/>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>-->
<div style="padding:5px 5px 0px 5px;">
    <div class="mini-toolbar" style="border-bottom:0;">
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <a class="mini-button" iconCls="icon-add" onclick="add">增加</a>
                    <a class="mini-button" iconCls="icon-edit" onclick="edit" id="edit_btn">编辑</a>
                    <a class="mini-button" iconCls="icon-remove" onclick="remove">删除</a>
                </td>
            </tr>
        </table>
    </div>
</div>

<div class="mini-fit" style="padding:0px 5px 5px 5px;">
    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;"
         url="cqzd/sysconfig/sms/queryList" dataField="data" idField="id"  sizeList="[10,20,50,100]" multiSelect="true" onselectionchanged="selectionChanged">
        <div property="columns">
            <div type="checkcolumn"></div>
            <div field="tmplName" width="120" headerAlign="center" align="center" allowSort="true">模板名称</div>
            <div field="tmplContent" width="120" headerAlign="center" align="center" allowSort="true">模板内容</div>
            <div field="createUserName" width="120" headerAlign="center" align="center" allowSort="true">创建人</div>
            <div field="createTime" width="120" headerAlign="center" align="center" allowSort="true" dateFormat="yyyy-MM-dd hh:mm:ss">创建时间</div>
        </div>
    </div>
</div>

<script type="text/javascript">
    txkui.parse();

    var moduleUlr="cqzd/sysconfig/sms/",modulePageUlr= getHtmlPageUrl("sysconfig");
    var form = new mini.Form("#form1");
    var grid = mini.get("datagrid1");
    (function(){
        grid.load();
    })();

    //当选择列时
    function selectionChanged(){
      var rows = grid.getSelecteds();
      if(rows.length>1){
        mini.get("edit_btn").disable();
      }else{
          mini.get("edit_btn").enable();
      }
    }

    function add() {
        mini.open({
            url: modulePageUlr+"smstmpl_add.html",
            title: "新增短信模板",
            width: 500,
            height: 400,
            ondestroy: function (action) {
                if(action=="ok"){
                    grid.reload();
                }
            }
        });
    }

    function edit(){
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: modulePageUlr + "smstmpl_update.html",
                title: "修改短信模板", width: 500, height: 400,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = row;
                    data.action="update";
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    if(action=="ok"){
                        grid.reload();
                    }
                }
            });
        }else{
            mini.alert("请选中一条记录");
        }
    }

    function remove(){

        var rows = grid.getSelecteds();
        var ids = [];
        for (var i = 0, l = rows.length; i < l; i++) {
            var r = rows[i];
            ids.push(r.tmplId);
        }
        if (rows.length > 0) {
            mini.confirm("短信模板将被删除，确定？","删除确认",function(action){
                if(action!=="ok") return;
                var id = ids.join(',');
                var data={ids:id};
                HttpUtil.delete(moduleUlr+"delete", data, function (text) {
                    grid.reload();
                });
            });
        } else {
            alert("请选中一条记录");
        }
    }

    function search(){
        //校验
        form.validate();
        if (form.isValid()===false) return;

        var formData = form.getData(false, true);

        //var json = mini.encode(formData);
        grid.load(formData);
    }

    function resetForm(){
        form.reset();
    }



</script>

</body>
</html>